package com.ericsson.enap.modules.cdr.task;

import com.ericsson.common.domain.CollectBizTypeEnum;
import com.ericsson.common.domain.NetTypeEnum;
import com.ericsson.common.quartz.task.ManualTask;
import com.ericsson.common.util.LogFileName;
import com.ericsson.common.util.LoggerUtils;
import com.ericsson.enap.modules.cdr.entity.CdrCg;
import com.ericsson.enap.modules.cdr.service.CdrDownloadService;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.io.File;
import java.util.List;

/**
 * 5GC 话单下载
 */
@Lazy(true)
@Component
public class VgcCdrDownloadTask implements ManualTask {
    private Logger log = LoggerUtils.Logger(LogFileName.VgcCdrDownLoadJob);

    @Autowired
    private CdrDownloadService vgcCdrDownloadService;

    @Value("${collectorIp}")
    private String collectorIp;
    @Value("${baseDir}")
    private String baseDir;
    @Value("${cdrDataDir}")
    private String cdrDataDir;
    @Value("${vgccdrDownloadDir}")
    private String cdrDownloadDir;
    @Value("${vgccdrDownloadInterval}")
    private String vgccdrDownloadInterval;

    @Override
    public void execute() {
        log.info("VgcCdrDownLoadTask execute start");
        String vgcDownloadDir=this.baseDir+ File.separator+this.cdrDataDir+File.separator+this.cdrDownloadDir;
        List<CdrCg> vgcCgs=vgcCdrDownloadService.getCgList(Integer.parseInt(CollectBizTypeEnum.VGCCDRDownLoad.value()), Integer.parseInt(NetTypeEnum.CHF.value()),this.collectorIp);

        //根据采集器IP查询对应下载的VGCCG
        log.info("VgcCdrDownLoadTask execute vgcCgs size:"+vgcCgs.size());
        if(vgcCgs.size()>0){
            vgcCdrDownloadService.downloadCgCDRFile(Integer.parseInt(CollectBizTypeEnum.VGCCDRDownLoad.value()),vgcCgs,vgcDownloadDir,vgccdrDownloadInterval);
        }
        log.info("VgcCdrDownLoadTask execute end");
    }
}
